$(function() {
    const data = getParams(location.search)
        // console.log(data);
    $.ajax(`${baseurl}/posts/category/${data.id}`, {
        success: function(res) {
            if (res) {
                res.forEach(item => {
                    item.updateAt = moment(item.updateAt).format('YYYY-MM-DD');
                    item.content = item.content.substr(0, 150)
                })
            }

            // console.log('=================');
            console.log($('#listpid'));
            const newhtml = template('listpid', { title: data.title, listlist: res, baseurl: baseurl })
            $('.panel.new').html(newhtml)
        },
        error: function(err) {
            console.log('erre', err);
        }
    })


    // 获取地址栏参数
    function getParams(paramsStr) {
        if (!paramsStr) {
            return {}
        }
        const tempStr = paramsStr.substr(1)
        const tempArr = tempStr.split('&')
        let params = {}
        tempArr.forEach(itemStr => {
            const paramsArr = itemStr.split('=')

            params[paramsArr[0]] = decodeURI(paramsArr[1])
        });
        return params

    }
})